package com.feisi.service.impl;

import com.feisi.dao.UserDao;
import com.feisi.domain.User;
import com.feisi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public List<User> findAll(Integer page, Integer limit) {
        System.out.println("findAll被执行!");
        List<User> users = userDao.findAll(page,limit);
        System.out.println(users.get(0));
        return users;
    }

    @Override
    public Integer usersTotal() {
        Integer usersTotal = userDao.usersTotal();
        return usersTotal;
    }


    @Override
    public void saveUser(User user) {

        userDao.saveUser(user);

    }

    @Override
    public List<User> findByName(String u_name, Integer page, Integer limit) {
        List<User> users = userDao.findByName(u_name, page, limit);
        return users;
    }

    @Override
    public Integer usersTotalByName(String u_name) {
        Integer usersTotalByName = userDao.usersTotalByName(u_name);
        return usersTotalByName;
    }

    @Override
    public User findUserById(Integer id) {
        User user = userDao.findUserById(id);
        return user;
    }

    @Override
    public List<User> findByDepartment(String u_department, Integer page, Integer limit) {
        List<User> users = userDao.findByDepartment(u_department, page, limit);
        return users;
    }

    @Override
    public Integer userTotalByDepartment(String u_department) {
        Integer userTotalByDepartment = userDao.userTotalByDepartment(u_department);
        return userTotalByDepartment;
    }

    @Override
    public void updateUser(User user) {
        userDao.updateUser(user);
    }


    @Override
    public void updateUserPassword(Integer id, String password) {
        userDao.updateUserPassword(id,password );
    }

    @Override
    public List<User> findByNameAndPassword(String username, String password) {
        List<User> users = userDao.findByNameAndPassword(username, password);
        return users;
    }

    @Override
    public void deleteUser(Integer[] ids) {
        userDao.deleteUser(ids);
    }

}
